package csc.daonjpa.java.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 * Target accounts can be preregistered (accountNumber, accountOwner, bank,
 * branch)
 * 
 * When doing transfer user can choose from a predefined list (dropbox)
 */

@Entity
public class TargetAccount implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(name = "accountNumber", unique = true)
	private String accountNumber;

	@Column(name = "accountowner")
	private String accountOwner;

	@Column(name = "bank")
	private String bank;

	@Column(name = "branch")
	private String branch;

	@OneToMany(mappedBy = "tarAcc", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	private List<TransferTransaction> transactions;

	public List<TransferTransaction> getTransactions() {
		return transactions;
	}

	public void setTransactions(List<TransferTransaction> transactions) {
		this.transactions = transactions;
	}

	public void addTransaction(TransferTransaction transaction) {
		if (transactions == null) {
			transactions = new ArrayList<TransferTransaction>();
		}
		transaction.setTarAcc(this);
		transactions.add(transaction);
	}

	public String getAccountNumber() {
		return accountNumber;
	}

	public void setAccountNumber(String accountNumber) {
		this.accountNumber = accountNumber;
	}

	public String getAccountOwner() {
		return accountOwner;
	}

	public void setAccountOwner(String accountOwner) {
		this.accountOwner = accountOwner;
	}

	public String getBank() {
		return bank;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}

	public String getBranch() {
		return branch;
	}

	public void setBranch(String branch) {
		this.branch = branch;
	}
}
